/* eslint-disable @typescript-eslint/no-explicit-any */
import { IGlobalConfig } from '../interface';

/**
 * @description 全局配置控制器
 * @export
 * @class GlobalConfigController
 */
export class GlobalConfigController {
  /**
   * @description 全局配置
   * @private
   * @type {IGlobalConfig}
   * @memberof GlobalConfigController
   */
  private config!: IGlobalConfig;

  /**
   * Creates an instance of GlobalConfigController.
   * @param {IGlobalConfig} config
   * @memberof GlobalConfigController
   */
  constructor(config: IGlobalConfig) {
    this.setConfig(config);
  }

  /**
   * @description 过滤有效字段
   * @private
   * @param {any} config
   * @returns {IGlobalConfig}
   * @memberof GlobalConfigController
   */
  private filterValidFields(config: any): IGlobalConfig {
    return {
      startTime: config.startTime,
      endTime: config.endTime,
      headerRowHeight: config.headerRowHeight,
      headerBgColor: config.headerBgColor,
      headerTextColor: config.headerTextColor,
      resourceColumnWidth: config.resourceColumnWidth,
      resourceBodyRowHeight: config.resourceBodyRowHeight,
      resourceBodyBg: config.resourceBodyBg,
      resourceDriverColor: config.resourceDriverColor,
      scaleColumnWidth: config.scaleColumnWidth,
      scaleRange: config.scaleRange,
      scaleValue: config.scaleValue,
      scaleTextColor: config.scaleTextColor,
      scaleBodyBg: config.scaleBodyBg,
      gridLineColor: config.gridLineColor,
      allowDrag: config.allowDrag,
      dragInterval: config.dragInterval,
    };
  }

  /**
   * @description 设置全局配置
   * @param {IGlobalConfig} config
   * @memberof GlobalConfigController
   */
  setConfig(config: IGlobalConfig): void {
    this.config = this.filterValidFields(config);
  }

  /**
   * @description 获取全局配置
   * @returns {*}  {IGlobalConfig}
   * @memberof GlobalConfigController
   */
  getConfig(): IGlobalConfig {
    return this.config;
  }

  /**
   * @description 销毁
   * @memberof GlobalConfigController
   */
  destory(): void {}
}
